namespace CSharpPro._1013;

public class Demo
{
    //作业1
    public void TestPrint1()
    {
        Console.Write("请输入第一个整数: ");
        int x = int.Parse(Console.ReadLine());

        Console.Write("请输入第二个整数: ");
        int y = int.Parse(Console.ReadLine());

        Console.Write("请输入第三个整数: ");
        int z = int.Parse(Console.ReadLine());

        int[] numbers = { x, y, z };
        Array.Sort(numbers);

        Console.WriteLine("这三个数从小到大顺序为: " + numbers[0] + " " + numbers[1] + " " + numbers[2]);
    }

    public void TestPrint2()
    {
        Console.WriteLine("1-100之间所有不是7的倍数和不包含7的数字有:");
        int sum = 0;
        for (int i = 1; i <= 100; i++)
        {
            if (i % 7 == 0 || i % 10 == 7 || i / 10 == 7)
            {
                continue;
            }

            Console.Write(i + " ");
            sum += i;
        }

        Console.WriteLine("\n和为：" + sum);
    }

    public void TestPrint3()
    {
        Console.WriteLine("九九乘法表：");

        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                Console.Write(j + "×" + i + "=" + (i * j) + "\t");
            }

            Console.WriteLine();
        }
    }

    public void TestPrint4()
    {
        Console.WriteLine("1000以内的完数有：");

        for (int num = 2; num <= 1000; num++)
        {
            int sum = 0; 
            for (int i = 1; i < num; i++)
            {
                if (num % i == 0)
                {
                    sum += i;
                }
            }
            
            if (sum == num)
            {
                Console.Write(num + " ");
            }
        }
        
    }

    public void TestPrint5()
    {
        Console.Write("请输入一个正整数：");
        string input = Console.ReadLine();
        int number;
        
        if (!int.TryParse(input, out number) || number <= 0)
        {
            Console.WriteLine("输入无效，请输入一个正整数！");
            return;
        }
        
        int digits = input.Length;
        Console.WriteLine("该数字是 " + digits + " 位数");
        
        Console.Write("逆序打印各位数字：");
        for (int i = input.Length - 1; i >= 0; i--)
        {
            Console.Write(input[i] + " ");
        }
    }

    public void TestPrint6()
    {
        Console.Write("请输入菱形的行数：");
        int n = int.Parse(Console.ReadLine());

        for (int i = 1; i <= n; i += 2)
        {
            int space = (n - i) / 2;
            for (int j = 0; j < space; j++)
                Console.Write(" ");
            for (int j = 0; j < i; j++)
                Console.Write("*");
            Console.WriteLine();
        }

        for (int i = n - 2; i >= 1; i -= 2)
        {
            int space = (n - i) / 2;
            for (int j = 0; j < space; j++)
                Console.Write(" ");
            for (int j = 0; j < i; j++)
                Console.Write("*");
            Console.WriteLine();
        }
    }
}